﻿#region Copyright (c) 2013-06, Olaf Kober <amarok.projects@gmail.com>
//================================================================================
//	Permission is hereby granted, free of charge, to any person obtaining a copy
//	of this software and associated documentation files (the "Software"), to deal
//	in the Software without restriction, including without limitation the rights
//	to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//	copies of the Software, and to permit persons to whom the Software is
//	furnished to do so, subject to the following conditions:
//
//	The above copyright notice and this permission notice shall be included in
//	all copies or substantial portions of the Software.
//
//	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//	THE SOFTWARE.
//================================================================================
#endregion

using System;
using System.Threading.Tasks;
using System.Windows;


namespace Amarok.Presentation
{
	/// <summary>
	/// This type represents the interface of a view.
	/// </summary>
	public interface IView
	{
		/// <summary>
		/// Gets or sets the view model associated with the view.
		/// </summary>
		/// 
		/// <exception cref="InvalidOperationException">
		/// The calling thread does not have access to this System.Windows.Threading.DispatcherObject.</exception>
		Object ViewModel
		{
			get;
			set;
		}

		/// <summary>
		/// Gets a reference to the control that implements the view.
		/// </summary>
		/// 
		/// <exception cref="InvalidOperationException">
		/// The calling thread does not have access to this System.Windows.Threading.DispatcherObject.</exception>
		FrameworkElement Control
		{
			get;
		}


		/// <summary>
		/// Executes the specified action synchronously on the thread that the view was created on.
		/// </summary>
		/// 
		/// <param name="action">
		/// The action to execute, which takes no arguments and does not return a value.</param>
		/// 
		/// <exception cref="ArgumentNullException">
		/// A null reference was passed to a method that did not accept it as a valid argument.</exception>
		void Invoke(Action action);

		/// <summary>
		/// Executes the specified action asynchronously on the thread that the view was created on.
		/// </summary>
		/// 
		/// <param name="action">
		/// The action to execute, which takes no arguments and does not return a value.</param>
		/// 
		/// <returns>
		/// A task that represents the asynchronously running action. This task can be used to wait for completion, 
		/// to register a continuation and to access the state of the action.</returns>
		/// 
		/// <exception cref="ArgumentNullException">
		/// A null reference was passed to a method that did not accept it as a valid argument.</exception>
		Task InvokeAsync(Action action);


		/// <summary>
		/// Sends the specified view action synchronously to the thread that the view was created on, and 
		/// raises the view action attached event on the view.
		/// </summary>
		/// 
		/// <param name="viewAction">
		/// The view action to send to the view.</param>
		/// 
		/// <exception cref="ArgumentNullException">
		/// A null reference was passed to a method that did not accept it as a valid argument.</exception>
		void Send(ViewAction viewAction);

		/// <summary>
		/// Sends the specified view action asynchronously to the thread that the view was created on, and 
		/// raises the view action attached event on the view.
		/// </summary>
		/// 
		/// <param name="viewAction">
		/// The view action to send to the view.</param>
		/// 
		/// <returns>
		/// A task that represents the asynchronously running view action. This task can be used to wait for 
		/// completion, to register a continuation and to access the state of the view action execution.</returns>
		/// 
		/// <exception cref="ArgumentNullException">
		/// A null reference was passed to a method that did not accept it as a valid argument.</exception>
		Task SendAsync(ViewAction viewAction);

	}
}
